/**
 * 
 */
package sort.result;

import java.util.ArrayList;
import java.util.List;

/**
 * @author masaru-gotou
 *
 */
public class SortResultSummarizer {
	private List<SortResult> results = new ArrayList<SortResult>();
	
	public void add(SortResult result) {
		results.add(result);
	}
	public void clear() {
		results.clear();
	}
	public SortResultSummary getSummary() {
		SortResultSummary summary = new SortResultSummary();
		// �Z�o�s�v�̈�̃R�s�[
		summary.setArgorythmName(results.get(0).getAlgorithmName());
		summary.setRecordCount(results.get(0).getRecordCount());
		// ���s��
		summary.setExecCount(results.size());
		double elapsed_time_ttl = 0.0;
		double used_mem_ttl = 0.0;
		boolean sorted = true;
		boolean stabled = true;
		boolean validated = true;
		for (SortResult result : results) {
			elapsed_time_ttl += result.getElapsedTime();	// ���s����
			used_mem_ttl += result.getUsedMemory();	// �g�p������
			sorted &= result.isSorted();
			stabled &= result.isSorted();
			validated &= result.isValidated();
		}
		
		summary.setElapsedTimeAvg(elapsed_time_ttl / results.size() / 100);
		summary.setUsedMemoryAvg(used_mem_ttl / results.size() / 100);
		summary.setSorted(sorted);
		summary.setStabled(stabled);
		summary.setValidated(validated);
		
		return summary;
	}
}
